<script>
import BottomTabs from "../components/BottomTabs.vue"
import { reactive, ref } from 'vue';
import 'vant/es/toast/style';
export default {
     components:{
            BottomTabs
     },
    // 组合式api
    setup() {
        let obj = reactive({
            dolllist: "",
            prizelists: "",
            prizenum: ""
        })
        const show = ref(false);

        const active = ref(0);

        const showPopup = () => {
            show.value = true;
        };
        let getdolllistFun = () => {
            obj.dolllist = JSON.parse(window.localStorage.getItem("doll"));
            // console.log(obj.dolllist);
        }

        let getprizelistsFun = () => {
            obj.prizelists = JSON.parse(window.localStorage.getItem("prizelists"));
            obj.prizenum = JSON.parse(window.localStorage.getItem("prizenum"));
            console.log(obj.dolllist);
        }
        getprizelistsFun()
        getdolllistFun()
        return {
            active,
            show,
            showPopup,
            getprizelistsFun,
            obj,
            getdolllistFun
        };

    },
}
</script>

<template>
    <div class="activitylist">
        <div class="navbar-wrap">
            <div class="Navbarold">
                <nav>

                    <div class="navbar-title">活动</div>
                    <!-- <div class="navbar-button"></div> -->
                </nav>
            </div>
        </div>
        <van-tabs v-model:active="active" animated>
            <van-tab title="活动">
                <div class="activitybox">

                    <router-link custom to="/turntable" v-slot="{ href, navigate, isActive }">
                        <div class="boxitem" :href="href" @click="navigate" :class="[isActive && 'router-link-active']">
                            <div class="top">
                                <img src="../assets/images/title.png" alt="">
                            </div>
                            <div class="titletext">
                                <span>
                                    参加幸运大抽奖活动有机会赢取大额优惠券，中奖概率高，祝您好运连连
                                </span>
                            </div>
                        </div>
                    </router-link>


                    <router-link custom to="/activity" v-slot="{ href, navigate, isActive }">
                        <div class="boxitem" :href="href" @click="navigate" :class="[isActive && 'router-link-active']">
                            <div class="top">
                                <img src="../assets/images/抓娃娃.png" alt="">
                            </div>
                            <div class="titletext">
                                <span>
                                    参加娃娃机可以获取四款可爱的娃娃，上手简单，欢迎您的游玩
                                </span>
                            </div>
                        </div>
                    </router-link>


                </div>
            </van-tab>
            <van-tab title="兑换">

                <div class="exchangelist" style="">
                    <van-empty image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png"
                        image-size="80" description="没有可兑换的奖励"  v-if="obj.dolllist == null && obj.prizelists == null" />
                    <div class="dolllist" style="margin: 20px 0;" v-if="obj.dolllist != null">
                        <van-cell-group inset>
                            <van-cell value="娃娃兑换" style="background-color: #e0e0e0;" />
                            <van-cell is-link title="" @click="showPopup" v-for="item, index in obj.dolllist"
                                :key="index" style="border-bottom: 1px solid #f0f0f0;">
                                <!-- 使用 right-icon 插槽来自定义右侧图标 -->
                                <template #icon>
                                    <img :src="item" alt="" style="width: 30px;height: 30px;">
                                </template>

                                <template #value>
                                    <span>
                                        兑换码
                                    </span>
                                </template>
                            </van-cell>
                        </van-cell-group>

                    </div>

                    <div class="dolllist" style="margin: 20px 0;" v-if="obj.prizelists != null">

                        <van-cell-group inset>
                            <van-cell value="优惠卷兑换" style="background-color: #e0e0e0;" />
                            <div v-for="item, index in obj.prizelists" :key="index">
                                <van-cell :title="item.name" v-if="item.name != '谢谢惠顾'" style="border-bottom: 1px solid #f0f0f0;">
                                    <!-- 使用 right-icon 插槽来自定义右侧图标 -->
                                    <template #icon>
                                        <img :src="item.img" alt="" style="width: 30px;height: 30px;">
                                    </template>

                                    <template #value>
                                        <span>
                                            {{ obj.prizenum[index] }}
                                        </span>
                                    </template>
                                </van-cell>
                            </div>

                        </van-cell-group>

                    </div>
                </div>


            </van-tab>
        </van-tabs>
        <van-popup v-model:show="show">
            <div class="QR">
                <img src="../assets/images/QR.png" alt="">
            </div>
        </van-popup>
        <bottom-tabs :index="3"></bottom-tabs>
    </div>
</template>

<style lang="less">
.QR {
    width: 200px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;

    img {
        width: 170px;
        height: 170px;
    }
}

.custom-title {
    margin-right: 4px;
    vertical-align: middle;
}

.search-icon {
    font-size: 16px;
    line-height: inherit;
}

.activitylist {
    height: 100%;
    background-color: #f4f4f4;
    // background-color: #fff;

    .navbar-wrap {
        .Navbarold {
            background-color: #e54847 !important;
            height: 38px;
            overflow: hidden;
            position: relative;
            padding: 6px;
            box-sizing: content-box;


            &>nav {
                width: 100%;
                display: -webkit-box;
                text-align: center;
                display: flex;
                justify-content: center;

                .navbar-logo {
                    width: 100px;
                    background-size: 37%;

                    .navbar-back {
                        width: 36px;
                        height: 36px;
                        display: block;
                        z-index: 999;

                        &::after {
                            content: '';
                            position: absolute;
                            width: 13px;
                            height: 13px;
                            top: 16px;
                            left: 12px;
                            transform: rotate(45deg);
                            border: 2px solid #fff;
                            border-width: 0 0 2px 2px;
                        }
                    }
                }

                .navbar-title {
                    -webkit-box-flex: 1;
                    color: #fff;
                    font-size: 18px;
                    text-align: center;
                    line-height: 2;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    position: relative;
                }

                .navbar-button {
                    position: relative;
                    width: 100px;
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;
                }
            }
        }
    }

    // .activitybox:hover {
    //     // cursor: crosshair;
    //     box-shadow: 0px 5px 12px 1px #888;
    //     // background-color: black;
    // }

    .activitybox {
        width: 90%;

        margin: 20px auto;
        // background-color: #fff;



        .boxitem {
            margin-top: 30px;
            height: 130px;
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0px 2px 15px 1px #888;

            .top {
                width: 100%;
                height: 80px;
                overflow: hidden;
                // display: flex;
                position: relative;
                background-color: #e54847;

                img {

                    width: 120px;
                    height: 120px;
                    position: absolute;
                    left: 110px;
                    top: -24px;
                }
            }

            .titletext {
                // width: 200px;
                padding: 20px 10px;
                height: 50px;

                span {
                    display: block;
                    color: #a5a5a5;
                    width: 310px;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                    font-size: 12px;
                }
            }
        }

    }
}
</style>